package com.umeng.soexample.mvc.view.splash;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.umeng.soexample.R;
import com.umeng.soexample.mvc.control.SPHelperSave;
import com.umeng.soexample.mvc.view.helper.HelperActivity;
import com.umeng.soexample.mvp.view.HomeActivity;

/**
 * 启屏页
 */
public class SplashActivity extends AppCompatActivity {

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            toMainOrHelper();
        }
    };

    /**
     * 判断是跳转到主页面还是引导页
     */
    private void toMainOrHelper() {
        if (SPHelperSave.getInstance().isLogin()){
            toMain();
        }else{
            toHelper();
        }
    }

    /**
     * 跳转到引导页
     */
    private void toHelper() {
        Intent intent = new Intent(SplashActivity.this, HelperActivity.class);
        startActivity(intent);
        finish();
    }

    /**
     * 跳转到主页面
     */
    private void toMain() {
        Intent intent = new Intent(SplashActivity.this, HomeActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);

        handler.sendEmptyMessageDelayed(1, (1 * 1000));

    }
}
